CC=gcc
CXX=g++
LD=g++

CFLAGS=-g
CXXFLAGS=-g

INCLUDES=
LDFLAGS=

SRCS_cpp=$(wildcard *.cpp)
SRCS_c=$(wildcard *.c)
OBJS=$(SRCS_cpp:.cpp=.o) $(SRCS_c:.c=.o)
DIR_DEPS=.deps
DEPS=$(patsubst %.o,$(DIR_DEPS)/%.d,$(OBJS))

OUT=sample

all : $(OUT)

$(OUT) : $(OBJS)
	$(LD) $(LDFLAGS) $(OBJS) -o $(OUT)

%.o : %.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@

%.o : %.c
	$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@

$(DIR_DEPS)/%.d : %.cpp
	[ -d $(DIR_DEPS) ] || mkdir -p $(DIR_DEPS)
	$(CXX) -MM -MD $< -o $@

$(DIR_DEPS)/%.d : %.c
	[ -d $(DIR_DEPS) ] || mkdir -p $(DIR_DEPS)
	$(CC) -MM -MD $< -o $@

-include $(DEPS)

clean :
	rm -f *.d *.o $(OUT)
	@echo all cleaned

.PHONY : all clean
